﻿#pragma once


namespace MathUtils {
	constexpr double M_PI = 3.1415926535897932384;

	constexpr double Deg2Rad = M_PI / 180.0;
	constexpr double Rad2Deg = 180.0 / M_PI;
	constexpr double Epsilon = 0.000001;

	template <typename T>
	bool EqualZero(T a, T epsilon) {
		return a <= epsilon && a >= -epsilon;
	}

	template <typename T>
	bool Equal(
		T a,
		T b,
		T epsilon
	) {
		return EqualZero(a - b, epsilon);
	}

	template <typename T>
	bool Greater(
		T a,
		T b,
		T epsilon
	) {
		return a - b > epsilon;
	}

	template <typename T>
	bool Less(
		T a,
		T b,
		T epsilon
	) {
		return Greater(b, a, epsilon);
	}

	template <typename T>
	bool GreaterEqual(
		T a,
		T b,
		T epsilon
	) {
		return !Less(a, b, epsilon);
	}


	template <typename T>
	bool LessEqual(
		T a,
		T b,
		T epsilon
	) {
		return !Greater(a, b, epsilon);
	}

	inline int high_bit(int n) {
		if (n <= 0) {
			return -1; // 返回一个表示错误的值
		}

		int position = 0;

		while (n >>= 1) {
			position++;
		}

		return position;
	}
};
